"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Created by liuhe on 2017/05/31.
 */
('use strict');
const mongoose = require("mongoose");
let pageInfoSchema = new mongoose.Schema({
    siteInfo: {
        type: mongoose.Schema.Types.ObjectId,
        required: true,
        ref: 'GlobalSetup'
    },
    tplCode: { type: String, required: true },
    platform: { type: String, required: true, enum: ['pc', 'weixin', 'app', 'pad'] },
    pageType: { type: String, required: true },
    pageCode: { type: String, required: true },
    status: { type: String, required: true, enum: ['published', 'notpublished'] },
    updateTime: { type: Date, required: true },
    activated: { type: Boolean },
    shareInfo: { imgSrc: String, title: String, desc: String },
    isDoublePlatformTpl: { type: Boolean },
    pageStyle: { type: String },
    title: { type: String, default: '页面标题' },
    skinType: String,
    headLv: { type: Number, enum: [0, 1, 2, 3] },
    footLv: { type: Number, enum: [0, 1, 2, 3] },
    configOrder: { type: mongoose.Schema.Types.Mixed, required: true } //页面配置清单
});
//访问地址是固定规则生成的 用虚拟属性返回就行了
pageInfoSchema.virtual('url').get(function () {
    let url = '/';
    if (this.pageType !== 'index') {
        url = this.platform === 'pc' ? `/${this.pageType}/${this.pageCode}` : `#/${this.pageType}/${this.pageCode}`;
    }
    return url;
});
//编辑地址是固定规则生成的 用虚拟属性返回就行了
pageInfoSchema.virtual('editURL').get(function () {
    return `/mysite/${this.platform}/${this.pageType}/${this.pageCode}`;
});
pageInfoSchema.virtual('id').get(function () {
    return this._id;
});
//确保查询结果以json返回时包含虚拟字段
pageInfoSchema.set('toJSON', { getters: true, virtual: true });
exports.default = mongoose.model('PageInfo', pageInfoSchema);
